package com.bff.slimserver.musicjukebox.ui;

import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.bjj.ui.component.BJJPanel;
import java.awt.Dimension;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import org.bff.slimserver.SlimServer;
import org.bff.slimserver.exception.SlimConnectionException;
import org.bff.slimserver.exception.SlimException;

/**
 *
 * @author  bfindeisen
 */
public class PreferencesPanel extends BJJPanel {
    private SlimServer slimServer;
    
    public PreferencesPanel() {
        initComponents();
        try {
            this.slimServer = JukeboxProperties.getInstance().getSlimServer();
        } catch (SlimConnectionException ex) {
            Logger.getLogger(PreferencesPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        setLabels();
        setPreferredSize(new Dimension(350,150));
    }

    /** 
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblPlaylistDirectory = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lblSCVersion = new javax.swing.JLabel();
        cbMediaDirs = new javax.swing.JComboBox();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Preferences"));
        setLayout(new java.awt.GridBagLayout());

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("messages"); // NOI18N
        jLabel1.setText(bundle.getString("LABEL_MEDIA_DIRS")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(7, 0, 0, 5);
        add(jLabel1, gridBagConstraints);

        jLabel3.setText("Playlist Directory:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(7, 0, 0, 5);
        add(jLabel3, gridBagConstraints);

        lblPlaylistDirectory.setText("jLabel2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(7, 0, 0, 0);
        add(lblPlaylistDirectory, gridBagConstraints);

        jLabel2.setText("SC Version:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(7, 0, 0, 5);
        add(jLabel2, gridBagConstraints);

        lblSCVersion.setText("jLabel2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(7, 0, 0, 0);
        add(lblSCVersion, gridBagConstraints);

        cbMediaDirs.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        add(cbMediaDirs, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbMediaDirs;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel lblPlaylistDirectory;
    private javax.swing.JLabel lblSCVersion;
    // End of variables declaration//GEN-END:variables

    private void setLabels() {
        try {
            lblSCVersion.setText(getSlimServer().getVersion());
            DefaultComboBoxModel cbModel = new DefaultComboBoxModel();
            for(String s : getSlimServer().getMediaDirectories()) {
                cbModel.addElement(s);
            }
            cbMediaDirs.setModel(cbModel);
            lblPlaylistDirectory.setText(getSlimServer().getPlaylistDirectory());
            
        } catch (SlimException ex) {
            Logger.getLogger(PreferencesPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @return the slimServer
     */
    public SlimServer getSlimServer() {
        return slimServer;
    }

    /**
     * @param slimServer the slimServer to set
     */
    public void setSlimServer(SlimServer slimServer) {
        this.slimServer = slimServer;
    }

}
